﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tracker.Models.DTO;
using tracker.Models.DAL;
using tracker.Models;
using tracker.Models.BLL;

namespace tracker.Controllers
{
    public class HandlerUpdateDeviceInfoController : Controller
    {
        //
        // GET: /HandlerUpdateDeviceInfo/
        [CallAjaxFilter]
        public JsonStringResult Index(
                string TrackerIconName,
                string ID,
                string trackername,
                string trackerpassword,
                string trackersimnumber,
                string TrackerTypestring
            )
        {
            string result = "";
            if (!String.IsNullOrEmpty(ID) && ID.Length > 0)
            {
                ID = ID.Substring(1, ID.Length - 1);
                DeviceDAL dvDAL = new DeviceDAL();
                EDevice dv = dvDAL.getByDeviceKeySecurity(ID);
                String currentUserGroupID = Session[Common.USER_GROUPID].ToString();
                if (dv == null)
                {
                    result = Common.FALSE;
                }
                else
                {
                    dv.DeviceName = trackername;
                    dv.Password = trackerpassword;
                    dv.PictureOfDevide = TrackerIconName;
                    dv.SimNumber = trackersimnumber;
                    dv.ModifyBy = Session[Common.USER].ToString();
                    dv.DeviceKeySecurity = ID;
                    //dv.DeviceTypeID = BDeviceType.SelectByDeviceTypeName(TrackerType).DeviceTypeID;
                    
                    //Update
                    result = dvDAL.update(dv);
                }
            }
            else
            {
                result = Common.FALSE;
            }
            if (result == "0")
            {
                result = Common.TRUE;
            }
            return new JsonStringResult(result);
        }

    }
}
